<html>
<head><meta charset="utf-8"><title>What is promotion? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html">What is promotion?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205598239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/205598239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#205598239">(Jul 31 2020 at 14:41)</a>:</h4>
<p>What exactly is promotion in rustc? is it like lambda lifting in functional compilers? just lifting closures / constants to the top level? Also, where can I find the rules governing what can and cannot be promoted?</p>



<a name="205598627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/205598627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#205598627">(Jul 31 2020 at 14:44)</a>:</h4>
<p>See <a href="https://github.com/rust-lang/const-eval/blob/master/promotion.md">https://github.com/rust-lang/const-eval/blob/master/promotion.md</a>,</p>
<p>const promotion allows for things like <code>let x: &amp;'static str = &amp;(3 + 4);</code> by <em>promoting</em> the result of <code>3 + 4</code> to a constant</p>



<a name="205598642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/205598642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#205598642">(Jul 31 2020 at 14:44)</a>:</h4>
<p>(someone should write <a href="https://rustc-dev-guide.rust-lang.org/mir/index.html?highlight=promotion#promoted-constants">https://rustc-dev-guide.rust-lang.org/mir/index.html?highlight=promotion#promoted-constants</a>)</p>



<a name="205598714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/205598714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#205598714">(Jul 31 2020 at 14:45)</a>:</h4>
<p>Someone wrote <a href="https://doc.rust-lang.org/stable/reference/destructors.html?highlight=promotion#constant-promotion">https://doc.rust-lang.org/stable/reference/destructors.html?highlight=promotion#constant-promotion</a> <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="205598780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/205598780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#205598780">(Jul 31 2020 at 14:46)</a>:</h4>
<p>but yes, the rustc internals should be documented</p>



<a name="205598852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/205598852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#205598852">(Jul 31 2020 at 14:46)</a>:</h4>
<p>I never think to check the reference.</p>



<a name="208946011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/208946011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#208946011">(Sep 03 2020 at 10:16)</a>:</h4>
<p>I didn't understand the first sentence of the link <span class="user-mention" data-user-id="124288">@oli</span> posted:</p>
<blockquote>
<p>Promotion of a value expression to a 'static slot occurs when the expression could be written in a constant, borrowed, and dereferencing that borrow where the expression was originally written, without changing the runtime behavior.</p>
</blockquote>



<a name="208946031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20promotion%3F/near/208946031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20promotion.3F.html#208946031">(Sep 03 2020 at 10:16)</a>:</h4>
<p>Could use a re-wording?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>